package com.zlx.exchange.admin.service.impl;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.zlx.exchange.admin.dao.AdminDao;
import com.zlx.exchange.admin.service.AdminService;
import com.zlx.exchange.domain.entity.Admin;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;


import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * (Admin)表服务实现类
 *
 * @author makejava
 * @since 2023-09-08 10:17:08
 */
@Transactional
@Service("adminService")
public class AdminServiceImpl implements AdminService {
    @Resource
    private AdminDao adminDao;

    /**
     * 账户登录
     *
     * @param username
     * @param password
     * @return
     */
    @Override
    public Admin queryByUsername(String username, String password) {
        return adminDao.selectOne(new LambdaQueryWrapper<Admin>()
                .eq(Admin::getUsername, username)
                .eq(Admin::getPassword, SecureUtil.md5(password)));
    }

    /**
     * 用户注册
     */
    @Override
    public Boolean register(String username, String password) {
        int insert = adminDao.insert(new Admin(null, username, SecureUtil.md5(password), String.valueOf(RandomUtil.randomInt(1000, 10000)), new Date(), null, 1));
        return insert > 0;
    }


}
